Shader "Unlit/NewUnlitShader"
{

    // 玻璃上的雨水
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Size("_Size", Range(0,50))=10
        _Banjin("_Banjin",Range(0.05,0.5)) = 0.1
        _RainInt("_RainInt",Range(0,0.5)) =0.01
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #define S(a,b,t) smoothstep(a,b,t)

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            float _Size,_RainInt,_Banjin;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {

                // 方案1
                // fixed4 col = fixed4(0.5, 0.1, 0.2, 1.0);
                // return col;

                // 方案3
            //    float4 col =0;
            //    float2 gv = frac(i.uv * _Size) ;
            //     col.rg = gv;
            //     return col;

                // 方案2
                float t = _Time.y;
                float4 col =0;
                float2 aspect = float2(3,1);
                float2 uv = i.uv;
                uv.y += t*0.025;
               float2 gv =  frac(uv * _Size*aspect) -0.5;
                // uv.y += t*0.25;
                // float2 gv = uv;
                // col.rg = gv;

            float x =0;
            float y = - sin(t + sin(t + sin(t)*0.5))*0.45;//匀速
            // float y =sin(t)*0.45;//匀速
            float2 dropPos = (gv - float2(x,y))/aspect;
                float drop = S(_Banjin,_RainInt,length(dropPos));
                // float drop = S(_Banjin,_RainInt,length(gv/aspect));
                col += drop;

                if(gv.x>0.45||gv.y>0.45) col = float4(1,0,0,1);
                col.a = 0.5;
                return col;

         
            }
            ENDCG
        }
    }
}
